package com.example.homework.service;

import com.example.homework.model.Teacher;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TeacherService {

    private List<Teacher> teacherList = new ArrayList<>();

    public void addTeacher(Teacher teacher) {
        teacherList.add(teacher);
    }

    public List<Teacher> getAllTeachers() {
        return teacherList;
    }

    public void deleteTeacher(String id) {
        teacherList.removeIf(teacher -> teacher.getId().equals(id));
    }

    public void updateTeacher(Teacher teacher) {
        for (int i = 0; i < teacherList.size(); i++) {
            if (teacherList.get(i).getId().equals(teacher.getId())) {
                teacherList.set(i, teacher);
                return;
            }
        }
    }
}

